package br.com.lis;

import java.util.ArrayList;

import android.content.Context;
import android.database.DataSetObserver;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.TextView;

public class CursoAdapter extends BaseAdapter {
	private Context context;
	private ArrayList<Curso> lista;
	
	
	
	
	public CursoAdapter(Context context, ArrayList<Curso> lista){
		this.context = context;
		this.lista = lista;
	}
	
	@Override
	public int getCount() {
		return lista.size();
	}

	@Override
	public Object getItem(int position) {
		return lista.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}	

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Curso curso = lista.get(position);
		View layout;
		
		if(convertView == null){
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			layout = inflater.inflate(R.layout.cursos, null);
		}
		else{
			layout = convertView;
		}
		

		TextView nome = (TextView) layout.findViewById(R.id.tvNomeCurso);
		nome.setText(curso.getNome());
		
		TextView descricao = (TextView) layout.findViewById(R.id.tvDescrCurso);
		descricao.setText(curso.getDescricao());
		
		TextView professor = (TextView) layout.findViewById(R.id.tvProfessorCurso);
		professor.setText(curso.getProfessor());
		
		TextView LabelProfessor = (TextView) layout.findViewById(R.id.LabelProf);
		
		LinearLayout llCursosProf = (LinearLayout)  layout.findViewById(R.id.llCursosProf);
		
		if(position % 2 == 0){
			layout.setBackgroundColor(Color.parseColor("#ffffff"));
			nome.setTextColor(Color.parseColor("#800080"));
			descricao.setTextColor(Color.parseColor("#DDA0DD"));
			professor.setTextColor(Color.parseColor("#DDA0DD"));
			LabelProfessor.setTextColor(Color.parseColor("#DDA0DD"));
			llCursosProf.setBackgroundColor(Color.parseColor("#ffffff"));
		}
		
		return layout;
	}
}
